﻿using MediatR;
using Tb.App.API.Applications.Command.Cultivation;
using Tb.App.Domain.Rabbit.Cultivation;
using Tb.App.ErrorCode;
using Tb.App.Infrastructure.Interfaces;

namespace Tb.App.API.Applications.CommandHandler.Cultivation
{
    /// <summary>
    /// 养殖免疫信息查询-命令
    /// </summary>
    public class GetImmunityQueryCommondHandler : IRequestHandler<GetImmunityQueryCommond, ApiResult<List<ImmunityModel>>>
    {
        private readonly IBaseRepository<ImmunityModel> immunityRep;

        public GetImmunityQueryCommondHandler(IBaseRepository<ImmunityModel> immunityRep)
        {
            this.immunityRep = immunityRep;
        }
        public Task<ApiResult<List<ImmunityModel>>> Handle(GetImmunityQueryCommond request, CancellationToken cancellationToken)
        {
            ApiResult<List<ImmunityModel>> result=new ApiResult<List<ImmunityModel>>();
            result.Code=ApiEnum.查询成功;
            result.Message=ApiEnum.查询成功.ToString();

            var list = immunityRep.GetAll().Where(x => !x.IsDel && x.Batch == request.Bath).ToList();

            result.Data= list;
            return Task.FromResult(result);
        }
    }
}
